function res = anifunV3(theta,phi,psi, t,R1,R2, L1, L2,M1,M2,g,p2,turn,height)

 if turn==1
     xoffset=0;
     dir=1;
 else
     xoffset=p2;
     dir=-1;
 end
 K = trebufunV3(theta,phi,psi, t,R1,R2, L1, L2,M1,M2,g);
% K = Stuff;
time = K(:,1);
theta = K(:,2);
phi = K(:,3);
psi=K(:,4);
thetadot=K(:,5);
phidot=K(:,6);
psidot=K(:,7);
L1positionx = xoffset+cos(theta)*L1*dir;
L1positiony = sin(theta)*L1;
R1positionx = xoffset+cos(theta)*-R1*dir;
R1positiony = sin(theta)*-R1;
R2positionx = R1positionx+cos(psi)*R2*dir;
R2positiony = R1positiony+sin(psi)*R2;
L2positionx = L1positionx + cos(phi)*L2*dir;
L2positiony = L1positiony + sin(phi)*L2;

maxX=max([L2positionx;L1positionx;R1positionx;R2positionx]);
minX=min([L2positionx;L1positionx;R1positionx;R2positionx]);
maxY=max([L2positiony;L1positiony;R1positiony;R2positiony]);
minY=min([L2positiony;L1positiony;R1positiony;R2positiony]);
maxX=max([maxX,-minX, p2+height/2]);
maxY=max([maxY,-minY ]);
% height=max([L1+L2 R1+R2]);

% figure('Name','FUN!','Position',[0,0,800*maxX*2/(height+maxY),800],'Color',[0 1 1])

% maxDim=max([maxX height+maxY])

 xlim([-height/2-10 p2+height/2+10]);
 ylim([0 p2+20]);
i=1;
hold on
line([0,height/2],[height,0],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 line([0,-height/2],[height,0],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 line([height/4,-height/4],[height/2,height/2],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 line([p2,p2+height/2],[height,0],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 line([p2,p2-height/2],[height,0],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 line([p2+height/4,p2-height/4],[height/2,height/2],'LineWidth',4,'Color',[184/255;135/255;59/255]);
 plot(0,0+height,'o','MarkerEdgeColor',[0,0,0],'MarkerSize',10,'LineWidth',2);
 plot(p2,0+height,'o','MarkerEdgeColor',[0,0,0],'MarkerSize',10,'LineWidth',2);

beam=line([ R1positionx(i), L1positionx(i)],[R1positiony(i)+height,L1positiony(i)+height],'LineWidth',2,'Color',[139/255;69/255;19/255]);
beam2=line([ R2positionx(i), R1positionx(i)],[R2positiony(i)+height,R1positiony(i)+height],'LineWidth',2,'Color',[139/255;69/255;19/255]);
sling=line([ L2positionx(i), L1positionx(i)],[L2positiony(i)+height,L1positiony(i)]+height);
pd=M2/(M1+M2)*2;
cd=M1/(M1+M2)/2;
projectile=rectangle('Position',[ L2positionx(i)-pd/2,L2positiony(i)-pd/2+height,pd,pd],'Curvature',[.8 .5],'FaceColor',[1,0,0]);
counterweight=rectangle('Position',[ R2positionx(i)-cd/2,R2positiony(i)-cd/2+height,cd,cd],'Curvature',[.1 .1],'FaceColor',[0 1 0]);
%     axis(

title('Trebuchet Position')

%hinge

   res(i) = getframe;
for i = 2:length(time)
     pause((time(i)-time(i-1))/1);
    set(beam,'XData',[ R1positionx(i),  L1positionx(i)]);
    set(beam,'YData',[R1positiony(i)+height,L1positiony(i)+height ]);
    set(beam2,'XData',[ R2positionx(i),  R1positionx(i)]);
    set(beam2,'YData',[R2positiony(i)+height,R1positiony(i)+height ]);
    set(sling,'XData',[ L2positionx(i), L1positionx(i)]);
    set(sling,'YData',[L2positiony(i)+height,L1positiony(i)+height ]);
    set(projectile,'Position',[ L2positionx(i)-pd/2,L2positiony(i)-pd/2+height,pd,pd]);
    set(counterweight,'Position',[ R2positionx(i)-cd/2,R2positiony(i)-cd/2+height,cd,cd]);
% plot(,, 'ro','MarkerSize',12);
% plot(L2positionx(i),L2positiony(i), 'bo','MarkerSize',12);
% plot(R2positionx(i),R2positiony(i), 'yo','MarkerSize',12);
% plot([L1positionx(i),R2positionx(i)],[L1positiony(i),R2positiony(i)],'g');
% plot([L1positionx(i),L2positionx(i)],[L1positiony(i),L2positiony(i)],'k');
  res(i) = getframe;

% legend('Sling Arm','Sling','Counterweight')
end
m=projectilepositions(L1, L2, theta(end), phi(end), thetadot(end), phidot(end), height);
time=m(:,1); x=xoffset+m(:,2)*dir; y=m(:,3);
% pmaxX=max([maxX x']);
% xlim( [-maxX pmaxX]   )
% ylim([0 (height+maxY)*(1+(pmaxX-maxX)/(2*maxX))])
% pd=max([pd (pmaxX+maxX)/100]);
for i=2:length(x)
    pause(time(i)-time(i-1));
 set(projectile,'Position',[x(i)-pd/2,y(i)-pd/2+height,pd,pd]);
end
res=x(end);
% movie(res,1,10)
end
%(200,0,280,0,2,10,5,10000,.1,4,-9.8)
% movie(M,n,fps)
% M - stored frames
% n - loops, there are additional options with this parameter
% fps - frames per second